#include <stdio.h>
#include "ledflashmode.h"
#include "gpio_config.h"
#include "debug.h"

int delaytime = 500;
int LedFlshMode = 0;

void GPIO_ControlLedLevel_INIT(void)
{
    GPIO_InitTypeDef GPIO_InitStructure1 = {0};

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    GPIO_InitStructure1.GPIO_Pin = GPIO_Led;
    GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure1.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure1);
}

void ModeChange(void)
{
    switch(LedFlshMode){
                        case LEDFLASH_1HZ:
                            LedFlshMode = LEDFLASH_2HZ;
                            delaytime = 250;
                            break;
                        case LEDFLASH_2HZ:
                            LedFlshMode = LEDFLASH_3HZ;
                            delaytime = 166;
                            break;
                        case LEDFLASH_3HZ:
                            LedFlshMode = LEDFLASH_1HZ;
                            delaytime = 500;
                            break;
                        default:
                            break;
                    }
}

void LedBlink(void)
{
    GPIO_WriteBit(GPIOA, GPIO_Led, Bit_SET);
    Delay_Ms(delaytime);
    GPIO_WriteBit(GPIOA, GPIO_Led, Bit_RESET);
    Delay_Ms(delaytime);
}
